package gp;

import java.util.ArrayList;
import java.util.List;

import firing.FiringTree;


public class EliteSelection implements SelectionStrategy {

    private IndexSelectionStrategy secondaryStrategy;
    
    public EliteSelection() {
	secondaryStrategy = new GreedyOverSelection();
    }
    
    @Override
    public List<FiringTree> getNextGen(List<FiringTree> prevGen) {
	List<FiringTree> result = new ArrayList<FiringTree>();
	for(int i=0;i<prevGen.size()/5;i++) { //add the top 20% without modification
	    result.add(prevGen.get(prevGen.size()-i-1).duplicate());
	}
	List<FiringTree> mutatedChildren = new ArrayList<FiringTree>();
	mutatedChildren = Generationator.getNextGen(prevGen,secondaryStrategy);
	for(int i=result.size();i<prevGen.size();i++) {
	    result.add(mutatedChildren.get(i));
	}
	return result;
    }
    
    public String toString() {
	return "Elite Selection";
    }
}
